package Data_base;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
//修改
public class Xiugai {
    public void xiugai() throws Exception
    {
        try {
            DB ty = new DB();
            Class.forName(ty.Driver_class);
            Connection conn = DriverManager.getConnection(ty.Database_url, ty.Database_user, ty.Database_password);
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入要修改的id:");
            String zh = sc.nextLine();
            System.out.print("请输入密码:");
            String mm = sc.nextLine();
            Statement state = conn.createStatement();   //容器
            String sql = "select * from users where id='" + zh + "' and password='" + mm + "'";
            ResultSet re = state.executeQuery(sql);
            if (re.next()) {
                System.out.println("密码正确,请输入你要修改的密码:");
                String xu = sc.nextLine();
                String xiugai="update users  set password='"+xu+"'where id='"+zh+"'";   //SQL语句
                state.executeUpdate(xiugai);         //将sql语句上传至数据库执行
                System.out.println("用户"+zh+"修改密码成功");
            } else {
                System.out.println("输入账号或密码错误");
            }
            conn.close();//关闭通道
    }catch(Exception e)
    {e.printStackTrace();
    }
 }


}
